package com.cskaoyan.config3;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 成员变量中的值从配置文件中来
 * @ConfigurationProperties 从配置文件中取值，并且通过set方法赋值
 * 容器中的组件中使用该注解 → 通过前缀+成员变量等于配置文件中的key
 * @author stone
 * @date 2022/07/15 10:20
 */
//@Configuration
//@Data // 提供set方法
//@ConfigurationProperties(prefix = "cskaoyan.datasource")
public class DataSourceConfiguration3 {
    //cskaoyan.datasource.driverClassName
    String driverClassName;
    String url;
    String username;
    String password;
    @Bean
    public DataSource dataSource3() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
